package com.qf.service.impl;

import com.qf.dao.UserdetailDao;
import com.qf.etype.UserdetailDto;
import com.qf.pojo.Userdetail;
import com.qf.service.UserdetailService;
import com.qf.util.StrUtil;
import com.qf.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lzy
 * @since 2020-11-28
 */
@Service
public class UserdetailServiceImpl  implements UserdetailService {

    @Autowired
    private UserdetailDao userdetailDao;

    @Override
    public R update(int uid, UserdetailDto userdetailDto) {
        if (userdetailDto != null) {
            if (StrUtil.checkNoEmpty(userdetailDto.getAddress(), userdetailDto.getBirthday(), userdetailDto.getImageUrl(),
                    userdetailDto.getNickname(), userdetailDto.getSex().toString())) {
                if (userdetailDao.updateByUid(uid,userdetailDto) > 0) {
                    return R.ok();
                }
            }
        }
        return R.fail("修改信息失败，请检查网络后重试");
    }

    @Override
    public R findOne(int uid) {
        if (uid > 0) {
            return R.ok(userdetailDao.selectByUid(uid));
        } else {
            return R.fail();
        }
    }
}
